{
  "name": "Case 44: Intelligent TRC Validator with Embedded DTAA Rules",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1Y46kJwUhQEERxMcHK2C6vO-_cVEUQyXq",
          "mode": "list",
          "cachedResultName": "Case 44 - Tax Residency Certificate Folder",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1Y46kJwUhQEERxMcHK2C6vO-_cVEUQyXq"
        },
        "event": "fileCreated",
        "options": {}
      },
      "id": "30ae7155-e379-463e-93e1-4996bc498f53",
      "name": "Monitor TRC Upload Folder",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -1904,
        0
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "id": "41b991ea-bf47-48d0-8592-16ac5dd4bdce",
      "name": "Download TRC Document",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -1712,
        0
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cloud.llamaindex.ai/api/v1/parsing/upload",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "d1c5f469-2d43-4bbf-87ef-478f70fde07b",
      "name": "Upload to Parser",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -1504,
        0
      ]
    },
    {
      "parameters": {
        "amount": 20
      },
      "id": "4d24627d-3102-4ebd-b4a6-bf2f752f5441",
      "name": "Wait for Parsing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -1280,
        0
      ],
      "webhookId": "111f17ee-55d5-49e2-b732-a896e432c1b6"
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload to Parser\"].json[\"id\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "a4766396-ce0f-4d76-8823-f8c1a0d61b30",
      "name": "Check Parsing Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -1056,
        0
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "SUCCESS",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "SUCCESS"
            },
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "PENDING",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "PENDING"
            }
          ]
        },
        "options": {}
      },
      "id": "26b8571b-ea38-4a9d-ada4-ab01fa7b7574",
      "name": "Route Based on Status",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -832,
        0
      ]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload to Parser\"].json[\"id\"] }}/result/markdown",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "12bd5ba3-70cc-4e2f-97fc-ca9bbef2d111",
      "name": "Extract Parsed Content",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -592,
        -96
      ]
    },
    {
      "parameters": {
        "text": "={{ $json.markdown }}",
        "attributes": {
          "attributes": [
            {
              "name": "Certificate_Reference",
              "description": "The unique reference number or document number of the TRC"
            },
            {
              "name": "Entity_Name",
              "description": "The legal registered name of the taxpayer entity"
            },
            {
              "name": "Tax_ID",
              "description": "The Tax Identification Number, UEN, or TIN of the entity"
            },
            {
              "name": "Issuing_Country",
              "description": "The country that issued this TRC"
            },
            {
              "name": "Recipient_Country",
              "description": "The country for which treaty benefits are being claimed"
            },
            {
              "name": "Treaty_Article_Number",
              "description": "The specific DTAA article number mentioned (e.g., Article 10, Article 11, Article 12)"
            },
            {
              "name": "Certificate_Start_Date",
              "description": "The effective start date in YYYY-MM-DD format"
            },
            {
              "name": "Certificate_End_Date",
              "description": "The expiry date in YYYY-MM-DD format"
            },
            {
              "name": "Mentioned_WHT_Rate",
              "description": "Any withholding tax rate percentage mentioned"
            }
          ]
        },
        "options": {}
      },
      "id": "7a7e3185-805a-4760-81e0-44f338f086e0",
      "name": "AI Data Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        -432,
        -96
      ]
    },
    {
      "parameters": {
        "jsCode": "// Get TRC data from AI Data Extractor node\nconst trcData = $input.first().json.output;\n\n// Get TRC data from AI Data Extractor node\nconsole.log('TRC Data:', JSON.stringify(trcData, null, 2));\n\n// EMBEDDED DTAA RULES DATABASE\nconst dtaaRules = {\n  \"Singapore-India\": {\n    \"Article_10_Dividends\": { \"rate\": 10, \"conditions\": \"Beneficial owner requirement\" },\n    \"Article_11_Interest\": { \"rate\": 10, \"conditions\": \"Beneficial owner requirement\" },\n    \"Article_12_Royalties_FTS\": { \"rate\": 10, \"conditions\": \"Technical services and royalties\" }\n  },\n  \"Singapore-USA\": {\n    \"Article_10_Dividends\": { \"rate\": 15, \"conditions\": \"Standard rate\" },\n    \"Article_11_Interest\": { \"rate\": 15, \"conditions\": \"Standard rate\" },\n    \"Article_12_Royalties\": { \"rate\": 15, \"conditions\": \"Industrial royalties\" }\n  },\n  \"Singapore-UK\": {\n    \"Article_10_Dividends\": { \"rate\": 10, \"conditions\": \"Beneficial owner requirement\" },\n    \"Article_11_Interest\": { \"rate\": 10, \"conditions\": \"Beneficial owner requirement\" },\n    \"Article_12_Royalties\": { \"rate\": 10, \"conditions\": \"Beneficial owner requirement\" }\n  },\n  \"USA-India\": {\n    \"Article_10_Dividends\": { \"rate\": 15, \"conditions\": \"Standard rate\" },\n    \"Article_11_Interest\": { \"rate\": 15, \"conditions\": \"Standard rate\" },\n    \"Article_12_Royalties_FTS\": { \"rate\": 15, \"conditions\": \"Royalties and technical fees\" }\n  },\n  \"UK-India\": {\n    \"Article_10_Dividends\": { \"rate\": 15, \"conditions\": \"Standard rate\" },\n    \"Article_11_Interest\": { \"rate\": 15, \"conditions\": \"Standard rate\" },\n    \"Article_12_Royalties_FTS\": { \"rate\": 15, \"conditions\": \"Technical services and royalties\" }\n  },\n  \"default_rates\": {\n    \"dividends\": 20,\n    \"interest\": 20,\n    \"royalties\": 20,\n    \"technical_services\": 25\n  }\n};\n\nconst validationDate = new Date().toISOString().split('T')[0];\n\n// Extract and clean the data\nconst issuingCountry = (trcData.Issuing_Country || '').trim();\nconst recipientCountry = (trcData.Recipient_Country || '').trim();\nconst treatyKey = `${issuingCountry}-${recipientCountry}`;\nconst reverseKey = `${recipientCountry}-${issuingCountry}`;\n\nconst expiryDate = trcData.Certificate_End_Date;\nconst isValid = expiryDate && new Date(expiryDate) >= new Date(validationDate);\nconst validationStatus = isValid ? 'Valid' : 'Expired';\n\nlet applicableTreaty = dtaaRules[treatyKey] || dtaaRules[reverseKey];\nlet treatyExists = !!applicableTreaty;\n\nconst articleNumber = (trcData.Treaty_Article_Number || '').trim();\nlet articleType = 'Unknown';\nlet treatyRate = null;\nlet applicableConditions = '';\n\nif (treatyExists && articleNumber) {\n  if (articleNumber.includes('10')) {\n    articleType = 'Dividends';\n    const articleKey = Object.keys(applicableTreaty).find(k => k.includes('Article_10'));\n    if (articleKey) {\n      treatyRate = applicableTreaty[articleKey].rate;\n      applicableConditions = applicableTreaty[articleKey].conditions;\n    }\n  } else if (articleNumber.includes('11')) {\n    articleType = 'Interest';\n    const articleKey = Object.keys(applicableTreaty).find(k => k.includes('Article_11'));\n    if (articleKey) {\n      treatyRate = applicableTreaty[articleKey].rate;\n      applicableConditions = applicableTreaty[articleKey].conditions;\n    }\n  } else if (articleNumber.includes('12')) {\n    articleType = 'Royalties/FTS';\n    const articleKey = Object.keys(applicableTreaty).find(k => k.includes('Article_12'));\n    if (articleKey) {\n      treatyRate = applicableTreaty[articleKey].rate;\n      applicableConditions = applicableTreaty[articleKey].conditions;\n    }\n  }\n}\n\nlet defaultRate = null;\nif (!treatyExists || !treatyRate) {\n  if (articleType === 'Dividends') defaultRate = dtaaRules.default_rates.dividends;\n  else if (articleType === 'Interest') defaultRate = dtaaRules.default_rates.interest;\n  else if (articleType === 'Royalties/FTS') defaultRate = dtaaRules.default_rates.royalties;\n  else defaultRate = dtaaRules.default_rates.technical_services;\n}\n\nconst applicableWHTRate = treatyRate || defaultRate;\nconst mentionedRateStr = (trcData.Mentioned_WHT_Rate || '').toString().trim();\nconst mentionedRate = mentionedRateStr ? parseFloat(mentionedRateStr.replace('%', '').replace(/[^0-9.]/g, '')) : null;\n\nlet riskLevel = 'Low';\nlet riskReasons = [];\n\nif (validationStatus === 'Expired') {\n  riskLevel = 'Critical';\n  riskReasons.push('TRC has expired');\n}\n\nif (!treatyExists) {\n  riskLevel = riskLevel === 'Critical' ? 'Critical' : 'High';\n  riskReasons.push(`No DTAA found for ${treatyKey}`);\n}\n\nif (mentionedRate && applicableWHTRate && mentionedRate < applicableWHTRate) {\n  riskLevel = 'High';\n  riskReasons.push(`Mentioned rate (${mentionedRate}%) is lower than applicable rate (${applicableWHTRate}%)`);\n}\n\nif (validationStatus === 'Valid' && treatyExists && (!mentionedRate || mentionedRate >= applicableWHTRate)) {\n  riskLevel = 'Low';\n}\n\nconst doubleTaxationApplies = !treatyExists || validationStatus === 'Expired';\nconst recommendedAction = doubleTaxationApplies \n  ? `Apply default WHT rate of ${defaultRate}% (No valid treaty benefit)` \n  : `Apply treaty WHT rate of ${treatyRate}% under ${articleNumber}`;\n\nlet complianceRecommendation = '';\nif (validationStatus === 'Expired') {\n  complianceRecommendation = 'URGENT: Request updated TRC from vendor before processing payment';\n} else if (!treatyExists) {\n  complianceRecommendation = 'WARNING: No DTAA exists. Apply default domestic WHT rates';\n} else if (riskLevel === 'High') {\n  complianceRecommendation = 'REVIEW: Verify beneficial ownership and treaty conditions before applying reduced rate';\n} else {\n  complianceRecommendation = 'APPROVED: Treaty benefits can be applied subject to documentation';\n}\n\nreturn {\n  json: {\n    Certificate_Reference: trcData.Certificate_Reference || 'N/A',\n    Entity_Name: trcData.Entity_Name || 'N/A',\n    Tax_ID: trcData.Tax_ID || 'N/A',\n    Issuing_Country: issuingCountry || 'N/A',\n    Recipient_Country: recipientCountry || 'N/A',\n    Certificate_Start_Date: trcData.Certificate_Start_Date || 'N/A',\n    Certificate_End_Date: trcData.Certificate_End_Date || 'N/A',\n    Treaty_Article: articleNumber || 'N/A',\n    Article_Type: articleType,\n    Treaty_Exists: treatyExists ? 'Yes' : 'No',\n    Mentioned_WHT_Rate: mentionedRate ? `${mentionedRate}%` : 'Not mentioned',\n    Treaty_WHT_Rate: treatyRate ? `${treatyRate}%` : 'N/A',\n    Default_WHT_Rate: `${defaultRate}%`,\n    Applicable_WHT_Rate: `${applicableWHTRate}%`,\n    Validation_Status: validationStatus,\n    Risk_Level: riskLevel,\n    Risk_Reasons: riskReasons.join('; ') || 'None',\n    Double_Taxation_Applies: doubleTaxationApplies ? 'YES' : 'NO',\n    Recommended_Action: recommendedAction,\n    Compliance_Recommendation: complianceRecommendation,\n    Processing_Timestamp: new Date().toISOString()\n  }\n};"
      },
      "id": "f593320f-32a5-4c0a-8e08-c36b92b5498c",
      "name": "Intelligent DTAA Analyzer",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -128,
        -96
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "110F4bjZpnNQSJ4XzZSwdExfrj6xJTtNHnfJPB9ZIP7M",
          "mode": "list",
          "cachedResultName": "Case_44_TRC_Validation_Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/110F4bjZpnNQSJ4XzZSwdExfrj6xJTtNHnfJPB9ZIP7M/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/110F4bjZpnNQSJ4XzZSwdExfrj6xJTtNHnfJPB9ZIP7M/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Certificate_Reference": "={{ $json.Certificate_Reference }}",
            "Entity_Name": "={{ $json.Entity_Name }}",
            "Tax_ID": "={{ $json.Tax_ID }}",
            "Issuing_Country": "={{ $json.Issuing_Country }}",
            "Recipient_Country": "={{ $json.Recipient_Country }}",
            "Certificate_Start_Date": "={{ $json.Certificate_Start_Date }}",
            "Certificate_End_Date": "={{ $json.Certificate_End_Date }}",
            "Treaty_Article": "={{ $json.Treaty_Article }}",
            "Article_Type": "={{ $json.Article_Type }}",
            "Treaty_Exists": "={{ $json.Treaty_Exists }}",
            "Mentioned_WHT_Rate": "={{ $json.Mentioned_WHT_Rate }}",
            "Treaty_WHT_Rate": "={{ $json.Treaty_WHT_Rate }}",
            "Default_WHT_Rate": "={{ $json.Default_WHT_Rate }}",
            "Applicable_WHT_Rate": "={{ $json.Applicable_WHT_Rate }}",
            "Validation_Status": "={{ $json.Validation_Status }}",
            "Risk_Level": "={{ $json.Risk_Level }}",
            "Risk_Reasons": "={{ $json.Risk_Reasons }}",
            "Double_Taxation_Applies": "={{ $json.Double_Taxation_Applies }}",
            "Recommended_Action": "={{ $json.Recommended_Action }}",
            "Compliance_Recommendation": "={{ $json.Compliance_Recommendation }}",
            "Processing_Timestamp": "={{ $json.Processing_Timestamp }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Certificate_Reference",
              "displayName": "Certificate_Reference",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Entity_Name",
              "displayName": "Entity_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tax_ID",
              "displayName": "Tax_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Issuing_Country",
              "displayName": "Issuing_Country",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Recipient_Country",
              "displayName": "Recipient_Country",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Certificate_Start_Date",
              "displayName": "Certificate_Start_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Certificate_End_Date",
              "displayName": "Certificate_End_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Treaty_Article",
              "displayName": "Treaty_Article",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Article_Type",
              "displayName": "Article_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Treaty_Exists",
              "displayName": "Treaty_Exists",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Mentioned_WHT_Rate",
              "displayName": "Mentioned_WHT_Rate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Treaty_WHT_Rate",
              "displayName": "Treaty_WHT_Rate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Default_WHT_Rate",
              "displayName": "Default_WHT_Rate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Applicable_WHT_Rate",
              "displayName": "Applicable_WHT_Rate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Validation_Status",
              "displayName": "Validation_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Risk_Level",
              "displayName": "Risk_Level",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Risk_Reasons",
              "displayName": "Risk_Reasons",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Double_Taxation_Applies",
              "displayName": "Double_Taxation_Applies",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Recommended_Action",
              "displayName": "Recommended_Action",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Compliance_Recommendation",
              "displayName": "Compliance_Recommendation",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Processing_Timestamp",
              "displayName": "Processing_Timestamp",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "295a667e-0370-4fc0-963a-b10bd4fb9cad",
      "name": "Log to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        16,
        -96
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "a0781d40-4ed4-48e0-8693-fa1be033b93f",
      "name": "OpenAI GPT-4o Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        -432,
        96
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "email_subject",
              "name": "email_subject",
              "value": "=TRC Validation Alert - {{ $json.Entity_Name }} ({{ $json.Validation_Status }})",
              "type": "string"
            },
            {
              "id": "email_body",
              "name": "email_body",
              "value": "=Dear Finance Team,\n\nA Tax Residency Certificate (TRC) has been processed and validated. Please review the summary below:\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📋 CERTIFICATE DETAILS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nCertificate Reference: {{ $json.Certificate_Reference }}\nEntity Name: {{ $json.Entity_Name }}\nTax ID: {{ $json.Tax_ID }}\nIssuing Country: {{ $json.Issuing_Country }}\nRecipient Country: {{ $json.Recipient_Country }}\nValidity Period: {{ $json.Certificate_Start_Date }} to {{ $json.Certificate_End_Date }}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📊 TREATY ANALYSIS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nTreaty Article: {{ $json.Treaty_Article }}\nIncome Type: {{ $json.Article_Type }}\nTreaty Exists: {{ $json.Treaty_Exists }}\nMentioned WHT Rate: {{ $json.Mentioned_WHT_Rate }}\nTreaty WHT Rate: {{ $json.Treaty_WHT_Rate }}\nDefault WHT Rate: {{ $json.Default_WHT_Rate }}\nApplicable WHT Rate: {{ $json.Applicable_WHT_Rate }}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n⚠️ VALIDATION RESULTS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nValidation Status: {{ $json.Validation_Status }}\nRisk Level: {{ $json.Risk_Level }}\nRisk Reasons: {{ $json.Risk_Reasons }}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n✅ DECISION & RECOMMENDATION\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nDouble Taxation Applies: {{ $json.Double_Taxation_Applies }}\nRecommended Action: {{ $json.Recommended_Action }}\n\nCompliance Recommendation:\n{{ $json.Compliance_Recommendation }}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nProcessed: {{ $json.Processing_Timestamp }}\n\nThis is an automated notification from the TRC Validation System.\nFor queries, contact the Tax Compliance Team.\n\nBest regards,\nAutomated TRC Validator",
              "type": "string"
            },
            {
              "id": "recipient_email",
              "name": "recipient_email",
              "value": "finance.head@company.com",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "c7fb1f29-9a96-4d06-867b-a45d227de83f",
      "name": "Prepare Email Content",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        192,
        -96
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipient_email }}",
        "subject": "={{ $json.email_subject }}",
        "emailType": "text",
        "message": "={{ $json.email_body }}",
        "options": {}
      },
      "id": "b314145d-f491-4ba2-aa0e-dbbf54f692dc",
      "name": "Send Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        400,
        -96
      ],
      "webhookId": "f394bc64-91ab-4593-9cee-c3db530053e9",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Monitor TRC Upload Folder": {
      "main": [
        [
          {
            "node": "Download TRC Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download TRC Document": {
      "main": [
        [
          {
            "node": "Upload to Parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Parser": {
      "main": [
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Parsing": {
      "main": [
        [
          {
            "node": "Check Parsing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Parsing Status": {
      "main": [
        [
          {
            "node": "Route Based on Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Based on Status": {
      "main": [
        [
          {
            "node": "Extract Parsed Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Parsed Content": {
      "main": [
        [
          {
            "node": "AI Data Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Data Extractor": {
      "main": [
        [
          {
            "node": "Intelligent DTAA Analyzer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Intelligent DTAA Analyzer": {
      "main": [
        [
          {
            "node": "Log to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4o Mini": {
      "ai_languageModel": [
        [
          {
            "node": "AI Data Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Log to Google Sheets": {
      "main": [
        [
          {
            "node": "Prepare Email Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Email Content": {
      "main": [
        [
          {
            "node": "Send Email via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e02f9de9-5e40-45c7-a020-d11924cb1fc2",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "GxOkFqT9ag797qpR",
  "tags": []
}